<template>
	<view class="task_item">
		<view class="font-14 font-weight-semibold flex-row flex-items-start flex-between" style="color: #313C56;">
			{{ task.name }}
		</view>
		<text class="font-12 font-weight-regular uv-line-1"
			style="margin-top: 5px; color: #95A4B3;">{{ task.classify }}</text>
		<view class="flex-row flex-between" style="margin-top: 9px;">
			<view class="flex-row flex-items-center">
				<!-- TODO  1 公司 2 团队 3 个人 -->
				<image v-if="task.bossType === 1" :src="task.head" style="height: 14px; width: 14px; min-width: 14px; border-radius: 14px;"></image>
				<image v-if="task.bossType === 2" :src="task.head" style="height: 14px; width: 14px; min-width: 14px; border-radius: 14px;"></image>
				<image v-if="task.bossType === 3" :src="task.head" style="height: 14px; width: 14px; min-width: 14px; border-radius: 14px;"></image>
				<text class="font-weight-medium"
					style="margin-left: 4px; white-space: nowrap;">{{ task.bossName }}</text>
				<image :src="`/static/user/b${task.bossLevel}.png`"
					style="margin-left: 3px; width: 30px; min-width: 30px; max-width: 30px;" mode="widthFix"></image>
			</view>
			<view class="font-12 font-weight-regular" style="color: #95A4B3; text-align: right;">
				{{ task.area }}
			</view>
		</view>

		<view class="flex-row flex-between" style="margin-top: 13px;">
			<view class="flex-row flex-items-end">
				<text class="font-20 font-weight-bold" style="color: #000000;">{{ task.totalAmount }}</text>
				<text class="font-12 font-weight-regular"
					style="color: #6B7885; margin-bottom: 2px; margin-left: 4px;">{{ task.chainName }}</text>
			</view>
			<view class="flex-row flex-items-center">
				<view class="task_item_btn task_item_btn__publish" @click="projectPublish()">
					发布类似
				</view>
				<view class="task_item_btn task_item_btn__im" @click="projectDetail(task.id)">
					立即咨询
				</view>
			</view>
		</view>
    <popup ref="popup1" msg="发布任务需要BOSS身份NFT，请前往购买!" btnTitle="前往" type="warning" @confirm="popupConfirm">
    </popup>
    <toast ref="toast"></toast>
	</view>
</template>

<script>
	import {
		getUserCenter
	} from "../../api";
	export default {
		name: "task-item",
		props: {
			task: {
				type: Object,
				default: () => {}
			},
			userLevel: {
				type: Number,
				default: () => 0
			},
		},
		data() {
			return {
				bossLevel: -1,
        digitalLevel: -1,
			};
		},
		methods: {
			projectDetail(id) {
				uni.navigateTo({
					url: '/pages/task-detail/task-detail?id=' + id
				})
			},

			async projectPublish() {
				await this.getUserCenter()
        if (this.bossLevel == -1) {
          this.$refs.toast.show({
            msg: '请登录后继续操作!'
          })
          return
        }
				if (this.bossLevel == 0) {
					console.error("bossLevel == 0, 弹窗并且不跳转")
          this.$refs.popup1.open()
					return
				}
				uni.navigateTo({
					url: '/pages/publish-task/publish-task'
				})
			},

      popupConfirm() {
        uni.navigateTo({
          url: '/pages/wallet/wallet'
        })
      },

			async getUserCenter() {
				await getUserCenter().then((data) => {
					if (data) {
						this.bossLevel = data.bossLevel
					}
				}).catch((res) => {})
			},

		}
	}
</script>

<style lang="scss">
	.task_item {
		background-color: #F7F9FD;
		border-radius: 10px;
		padding: 12px 16px;
		margin: 0px 12px 12px 12px;
		display: flex;
		flex-direction: column;
	}

	.task_item_btn {
		width: 72px;
		height: 24px;
		border-radius: 12px;
		font-size: 12px;
		font-weight: 400;
		display: flex;
		align-items: center;
		justify-content: center;

		&__publish {
			color: #6B7885;
			background-color: white;
			border: 1px solid #E9EAEB;
			margin-right: 8px;
		}

		&__im {
			background-color: #EB7520;
			color: white;
		}
	}
</style>